<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <%@ include file="/common/sale/include/common-base.jsp"%>
  <script src="${ctx}/js/jquery.cityselect-dict.js"></script>
  	
  <title>${titleName}</title>
</head>
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">
 <!-- top start -->
  <%@include file="/common/sale/top.jsp" %>
  <!-- top end -->


  <!-- left start -->
  <%@include file="/common/sale/left.jsp" %>
  <!-- left end-->
	<div class="content-wrapper">
        <section class="content">
          <div class="row">
	            <div class="col-xs-12">
		       <div class="box box-primary box-solid">
			    <div class="box-header with-border">
			              <h3 class="box-title">理财产品参数设置</h3>
			</div>
		<div class="modal-content">
			<div class="modal-body">
				<form class="form-horizontal" role="form" id="submitForm">
<!-- 					<input type="hidden" name="doCode" value="dymicSql"> -->
<!-- 					<input type="hidden" name="modelTypes" id="modelTypes" value="i_pubProdInfo"> -->
<!-- 					<input type="hidden" id="w_infoId" data-name="infoId" name="pubProdInfo.w_infoId"  value=""> -->
<!-- 					<input name="pubProdInfo.mainStatus"   type="hidden" value="0" /> -->
<!-- 					<input name="pubProdInfo.expStatus"  type="hidden" value="0" /> -->
<!-- 					<input name="pubProdInfo.delStatus"   type="hidden" value="F" /> -->
<!-- 					<input type="hidden" name="formToken" id="formToken" value=""> -->
			        <div class="box-body" id="submitFormData">
			          <!-- Custom Tabs -->
			          <div class="nav-tabs-custom">
			            <div class="tab-content">
			              <div class="tab-pane active" id="tab_1">
			               <div class="col-sm-12">
			               	<label class="col-sm-2 control-label" >产品编号:</label>
			                  <div class="col-sm-4">
			                    <div  class="form-group">
			                    <input type="text" id="proNo" name="pubProdInfo.proNo" class="form-control clean" data-bv-notempty="true" data-bv-notempty-message="商品编号不能为空！" >
			                    </div>
			                  </div>
			                  <label class="col-sm-2 control-label" >理财产品类型:</label>
			                  <div class="col-sm-4">
			                    <div class="form-group">
			                   		<select class="form-control"> 
			                   		<option>--请选择--</option>
			                  	 </select>
			                  	 </div>
			                  </div>
			                  <div class="col-sm-12">
				                  <label class="col-sm-2 control-label" >产品名称:</label>
				                  <div class="col-sm-4">
				                    <div  class="form-group">
				                    <textarea rows="2" cols="30"class="form-control clean"></textarea>
				                    </div>
				                  </div>
				                  <div class="col-sm-6">
				                  <label class="col-sm-4 control-label" >理财方式:</label>
				                  	<div class="col-sm-8">
			                   			 <div class="form-group">
			                   				<select class="form-control"> 
			                   					<option>--请选择--</option>
			                  				 </select>
			                  			  </div>
			                 		 </div>
			                  	   <label class="col-sm-4 control-label" >理财凭证:</label>
				                  	<div class="col-sm-8">
			                   			 <div class="form-group">
			                   				<select class="form-control"> 
			                   					<option>--请选择--</option>
			                  				 </select>
			                  			  </div>
			                 		 </div>
				                  </div>
			                  </div>
			                  
			                  
			                   
			                   <div class="col-sm-12">
					                 <label class="col-sm-2 control-label" >渠道:</label>
				                  <div class="col-sm-4">
				                    <div class="form-group">
				                   		<select class="form-control"> 
				                   		<option>--请选择--</option>
				                  	 </select>
				                  	 </div>
				                  </div>
					                <label class="col-sm-2 control-label" >产品评分:</label>
				                  <div class="col-sm-4">
				                    <div  class="form-group">
				                    <input type="text" id="proNameShort" name="pubProdInfo.proNameShort" class="form-control clean" data-bv-notempty="true"  >
				                    </div>
				                  </div>
			                  </div>
			                   <div class="col-sm-12">
				                 <label class="col-sm-2 control-label" >额度管理级别:</label>
			                  <div class="col-sm-4">
			                    <div class="form-group">
			                   		<select class="form-control"> 
			                   		<option>--请选择--</option>
			                  	 </select>
			                  	 </div>
			                  </div>
				                <label class="col-sm-2 control-label" >资金上存级别:</label>
			                  <div class="col-sm-4">
			                    <div class="form-group">
			                   		<select class="form-control"> 
			                   		<option>--请选择--</option>
			                  	 </select>
			                  	 </div>
			                  </div>
			                  </div>
			                  
			                   <div class="col-sm-12">
				                 <label class="col-sm-2 control-label" >产品状态:</label>
			                  <div class="col-sm-4">
			                    <div class="form-group">
			                   		<select class="form-control"> 
			                   		<option>--请选择--</option>
			                  	 </select>
			                  	 </div>
			                  </div>
				                <label class="col-sm-2 control-label" >业务代号:</label>
			                  <div class="col-sm-4">
			                    <div  class="form-group">
			                    <input type="text" id="proNameShort" name="pubProdInfo.proNameShort" class="form-control clean" data-bv-notempty="true"  >
			                    </div>
			                  </div>
			                  </div>
			                  
			                    <div class="col-sm-12">
			                     <label class="col-sm-2 control-label" >业务分类:</label>
			                  <div class="col-sm-4">
			                    <div  class="form-group">
			                    <input type="text" id="proNameShort" name="pubProdInfo.proNameShort" class="form-control clean" data-bv-notempty="true"  >
			                    </div>
			                  </div>
				                 <label class="col-sm-2 control-label" >收益币种:</label>
			                  <div class="col-sm-4">
			                    <div class="form-group">
			                   		<select class="form-control"> 
			                   		<option>--请选择--</option>
			                  	 </select>
			                  	 </div>
			                  </div>
			                  
			                    <div class="col-sm-12">
			                    <label class="col-sm-2 control-label" >额度批号:</label>
			                  <div class="col-sm-4">
			                    <div  class="form-group">
			                    <input type="text" id="proNameShort" name="pubProdInfo.proNameShort" class="form-control clean" data-bv-notempty="true"  >
			                    </div>
			                  </div>
				                 <label class="col-sm-2 control-label" >总额度:</label>
			                  <div class="col-sm-4">
			                    <div  class="form-group">
			                    <input type="text" id="proNameShort" name="pubProdInfo.proNameShort" class="form-control clean" data-bv-notempty="true"  >
			                    </div>
			                  </div>
				               
			                  
				              
			                  </div>
			              </div>					             
			              <!-- /.tab-pane -->
			            </div>
			            <!-- /.tab-content -->
			          </div>
			          <!-- nav-tabs-custom -->
			        </div>
	                <div class="box-footer">
	                <center>
	            	 		  <button class="btn btn-danger" type="button" onclick="submitForm('saveForm');">
	            	 		                             保存并提交审核
	            	 		  </button>
	            	 		  <button class= "btn btn-primary" type="button" onclick="backhome()">返回</button>
			         </center>
		            </div>
				</form>
			</div>
		</div>
		<!-- /.modal-content -->
            		<!-- /.box-body -->
          		</div>
           </div>
        </section>
	</div>
</div>
    <!-- foot start -->
  <%@include file="/common/sale/foot.jsp" %>
  <!-- foot start -->
  <!-- right start -->
  <%@include file="/common/default/right.jsp" %>
  <!-- right start -->
 </div> 
	</body>
	
	<script type="text/template" id="detailList-template">
		<? for ( var i = 0; i < rows.length; i++) {?>
			<tr>
				<td><?=rows[i].diyaName?></td>
				<td>
					<button type="button" class="btn btn-xs btn-primary" onclick="toEdit('<?=rows[i].type?>','<?=rows[i].infoId?>');">修改</button>
						&nbsp;&nbsp;
					<button type="button" class="btn btn-xs btn-danger" onclick="del('<?=rows[i].type?>','<?=rows[i].infoId?>');">删除</button>
				</td>
			</tr>
		<?}?>
</script>
</html>
<script>

var formId='saveForm';
var defaultTab = '#tab_1';
var modalType="i_trpDiya";

var clickMenu= 'financial-products';
var dateObject = $('.date').datepicker( {
	language : 'zh-CN',
	//inline: true,
	todayBtn : "linked",
	format : "yyyy-mm-dd",
    autoclose: true
});

$(function(){
	setValidate("saveForm");
	
	var diyaId="${param.diyaId}";
	if(diyaId!=null &&diyaId!=""){
		getInfoById(diyaId);
	}else{
		initDiyaId();
	}
});
	

function toAdd(type){
   $("#my_modal_"+type).modal("show");
   var objName="pubDiya"+replaceStr(type)+"Info";
   $("#"+type+"Form").find("[name='modelTypes']").val("i_"+objName);

   FormUtil.cleanDataByClass(type+"Form");
}


function toEdit(type,infoId){
	$("#my_modal_"+type).modal("show");
	loadDetailInfo(infoId,type);
}


function cannel(id){
	$('#'+id).modal('hide');
}

function backhome(){
	window.location.href="${page_admin}/pro/diya/diya-list";
}

function del(type,id){
	if(id =="undefined"){
		alert("请先选中一条数据！");
		return;
	}else{
		var objName="pubDiya"+replaceStr(type)+"Info";
		var conditionCol = objName+".w_infoId";
		$.ajax({ 
			type:'post',
			url:common_submit_url,
			dataType:'json',
		    data:"doCode=dymicSql"+"&modelTypes="+"d_"+objName+"&"+conditionCol+"="+id,
		    success: function(myData){
		    	alert(myData.msg);
	    		var diyaId = $("#saveForm .diyaId").val();

	    		loadDiyaDetail(diyaId);

		  	}
		});	
	}
}


function submitModalForm(formId,modalId,type){
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    dataType:'json',
	    success: function(myData){
	    	//console.log(myData);
	    	if(myData.flag=='T'){
	    		alert("操作成功！");
	    		$("#"+modalId).modal('hide');
	    		
	    		var diyaId = $("#"+formId+" .diyaId").val();
	    		//alert(diyaId);
	    		loadDiyaDetail(diyaId);
	    	}else{
	    		alert(myData.msg);
	    	}
	  	}
	});	
}
function submitForm(formId){
<%--	if(tabId!=null && tabId!="" && tabId!="undefined"){--%>
<%--		$('#'+formId).data('bootstrapValidator').validate();  --%>
<%--		if(!$('#'+formId).data('bootstrapValidator').isValid()){  --%>
<%--		    return ;  --%>
<%--		}  --%>
<%--	}else{--%>
<%--		var proName = $("#dyName").val();--%>
<%--		var proNum = $("#dyPhone").val();--%>
<%--		--%>
<%--		if(proName==null || proName==""){--%>
<%--			layer.alert('单位名称或姓名不能为空!', {--%>
<%--			    closeBtn: 0--%>
<%--			  });--%>
<%--			return ;--%>
<%--		}--%>
<%--		--%>
<%--		if(proNum==null || proNum==""){--%>
<%--			layer.alert('电话号码不能为空！！！',{--%>
<%--			  closeBtn: 0--%>
<%--			});--%>
<%--			return ;--%>
<%--		}--%>
<%--		--%>
<%--		--%>
<%--		--%>
<%--	}--%>
	
	var index_load = layer.load(1, {shade: false});
	$.ajax({
	    type:'post',
	    url:common_submit_url,
	    data:$("#"+formId).serialize(),
	    dataType:'json',
	    success: function(myData){ 
	         //console.log(myData);
		     layer.close(index_load);
	     		layer.alert(myData.msg, {closeBtn: 0,offset: '220px'},
	     				function(){
	     			
	     					if(myData.flag=="T"){
						 		window.location.href="${page_admin}/pro/diya/diya-list";
	     					}
	     				}
	     		);


	  	},
	     error: function (e) {
	    	 //console.log(e);
		     layer.close(index_load);
     	} 
   	 

	});	
}

function setValidate(formId){
}

function getInfoById(id){
	
	//加载抵押主表
	$.ajax({
	    type:'get',
	    url:common_info_url,
	    data:{"trpDiya.w_diyaId":id,"pageName":"nyt-trpDiya-list","formName":"searchForm","doCode":"dymicSql"},
	    async:false,
	    dataType:'json',
	    success: function(myData){
	    	 FormUtil.fillData("#saveForm", myData,"id");
			 $("#formName").val("editForm");
			//加载抵押子表
			loadDiyaDetail(id);
			 $("#citySelect").citySelect({  
				    prov:myData.diyaProvince,
				    city:myData.diyaCity,
				    dist:myData.diyaCountry,
				    nodata:"" //当子集无数据时，隐藏select 
			 });
	  	}
	    
	});
	
	
}



function loadDiyaDetail(diyaId){
	deleteAllRow("detailList");
	if(diyaId==null || diyaId=="" || diyaId=="undefined"){
		diyaId = $("#saveForm .diyaId").val();
	}
	var data=["td","cl","ss","bd","qt"];
	for(i=0;i<data.length;i++){
		var type=data[i];
		
		var objName = "pubDiya"+replaceStr(type)+"Info";
		var conditionCol = objName+".w_diyaId";
		$.ajax({
		    type:'get',
		    url:common_list_url,
		    //data:{"pubDiyaTdInfo.w_diyaId":diyaId,"doCode":"dymicSql","modelTypes":"s_pubDiyaTdInfo"},
		    data:"doCode=dymicSql"+"&modelTypes="+"s_"+objName+"&"+conditionCol+"="+diyaId,
		    async:false,
		    dataType:'json',
		    success: function(myData){
		    	//console.log(myData);
		    	if(myData.total>0){
		    		for(j=0;j<myData.total;j++){
		    			myData.rows[j].type=type;
		    		}
		    		var data = baidu.template("detailList-template",myData);  
					$("#detailList").append(data);
		    	}
		    	
		  	}
		    
		});
	}
	
	
}


function loadDetailInfo(infoId,type){
	var objName = "pubDiya"+replaceStr(type)+"Info";
	var conditionCol = objName+".w_infoId";
	$.ajax({
	    type:'get',
	    url:common_info_url,
	   // data:{"eval(conditionCol)":infoId,"doCode":"dymicSql","modelTypes":"s_"+objName},
	   data:"doCode=dymicSql"+"&modelTypes="+"s_"+objName+"&"+conditionCol+"="+infoId,
	    async:false,
	    dataType:'json',
	    success: function(myData){
	    	console.log(myData);
	    	 FormUtil.fillData("#"+type+"Form", myData,"id");
	    	 $("#"+type+"Form").find("[name='modelTypes']").val("u_"+objName);
	    	 $("#"+type+"Form").find("[name='"+objName+".w_infoId']").val(infoId);
	  	}
	    
	});
}

function initDiyaId(){
	$.ajax({
	    type:'get',
	    url:'${ctx}/sendPage/token?token=true',
	    dataType:'text',
	    success: function(myData){
			 $(".diyaId").val(myData);
	  	}
	});	
}

function deleteAllRow(tableId){
	var tb = document.getElementById(tableId);
	if(tb){
	     var rowNum=tb.rows.length;
	     for (i=0;i<rowNum;i++){
	         tb.deleteRow(i);
	         rowNum=rowNum-1;
	         i=i-1;
	     }
     }
}
</script>



